home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / Images .adf / Developers_Den / negative.c < prev    next >
C/C++ Source or Header  |  1991-11-08  |  3KB  |  115 lines

  1. /*
  2.  * negative.c - Does a simple negative in Imagemaster
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. struct jackinbuff
  8.   {
  9.     unsigned char *red;
  10.     unsigned char *green;
  11.     unsigned char *blue;
  12.     unsigned char *mask;
  13.     unsigned short x;
  14.     unsigned short y;
  15.   };
  16.  
  17. struct jackina
  18.   {
  19.     struct jackinbuff *primary;
  20.     struct jackinbuff *secondary;
  21.     struct jackinbuff *undo;
  22.     struct jackinbuff *blend;
  23.     struct jackinbuff *brush;
  24.     unsigned char     *mask;
  25.     char              jack[4];
  26.   };
  27.  
  28. static struct jackina *jackins;
  29. static struct jackinbuff *primary_jack;
  30. static struct jackinbuff *secondary_jack;
  31. static struct jackinbuff *undo_jack;
  32. static struct jackinbuff *blend_jack;
  33. static struct jackinbuff *brush_jack;
  34.  
  35.  
  36. main(argc,argv)
  37. int    argc;
  38. char   *argv[];
  39.   {
  40.   unsigned int tpoint,x,y,xw,yw,offset,yoffset;
  41.   unsigned char rr,gg,bb;
  42.   
  43.   unsigned char *rbu;
  44.   unsigned char *gbu;
  45.   unsigned char *bbu;
  46.   
  47.     printf("NEGATIVE <pointer to IM jackin structure>\n");
  48.     printf("A simple Imagemaster Public Interface operation.\n");
  49.   
  50.     if (argc <= 1)
  51.       {
  52.         printf("NEGATIVE : No argument supplied!\n");
  53.         return(1);
  54.       }
  55.     else
  56.       {
  57.         sscanf(argv[1],"%X",&tpoint);
  58.       }
  59.     if (tpoint == 0)
  60.       {
  61.         printf("NEGATIVE : Argument is ZERO!\n");
  62.         return(1);
  63.       }
  64.       
  65.     jackins = (struct jackina *)tpoint;
  66.       
  67.     if (jackins->jack[0] != 'J' ||
  68.         jackins->jack[1] != 'A' ||
  69.         jackins->jack[2] != 'C' ||
  70.         jackins->jack[3] != 'K' )
  71.       {
  72.         printf("NEGATIVE : Problem in information passed from Imagemaster!\n");
  73.         return(1);
  74.       }
  75.     if (jackins->primary == NULL)
  76.       {
  77.         printf("NEGATIVE : Primary buffer is NULL!\n");
  78.         return(1);
  79.       }
  80.     xw = jackins->primary->x;
  81.     yw = jackins->primary->y;
  82.     if (xw == 0 || yw == 0)
  83.       {
  84.         printf("NEGATIVE : Primary buffer is Empty!\n");
  85.         return(1);
  86.       }
  87.     rbu = jackins->primary->red;
  88.     gbu = jackins->primary->green;
  89.     bbu = jackins->primary->blue;
  90.     if (rbu == NULL || gbu == NULL || bbu == NULL)
  91.       {
  92.         printf("NEGATIVE : Primary buffer is corrupted!\n");
  93.         return(1);
  94.       }
  95.     /* Run through the image */
  96.     for (y=0; y<yw; y++)
  97.       {
  98.         printf(".");
  99.         yoffset = y * xw;
  100.         for (x=0; x<=xw; x++)
  101.           {
  102.             offset = yoffset + x;
  103.             rr = *(rbu+offset);
  104.             gg = *(gbu+offset);
  105.             bb = *(bbu+offset);
  106.             *(rbu+offset) = 255 - rr;  /* This is a color negative */
  107.             *(gbu+offset) = 255 - gg;
  108.             *(bbu+offset) = 255 - bb;
  109.           }
  110.       }
  111.     printf("\n");
  112.     return(0);
  113.   }
  114.  
  115.